package cn.gcyl.module.biz.controller.admin.collect;

import cn.gcyl.framework.apilog.core.annotation.ApiAccessLog;
import cn.gcyl.framework.common.pojo.CommonResult;
import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.util.object.BeanUtils;
import cn.gcyl.framework.excel.core.util.ExcelUtils;
import cn.gcyl.module.biz.controller.admin.collect.vo.*;
import cn.gcyl.module.biz.dal.dataobject.collect.CollectDO;
import cn.gcyl.module.biz.service.collect.CollectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.gcyl.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.gcyl.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 收藏信息")
@RestController
@RequestMapping("/biz/collect")
@Validated
public class CollectController {

    @Resource
    private CollectService collectService;

    @PostMapping("/create")
    @Operation(summary = "创建收藏信息")
//    @PreAuthorize("@ss.hasPermission('biz:collect:create')")
    public CommonResult<Long> createCollect(@Valid @RequestBody CollectSaveReqVO createReqVO) {
        return success(collectService.createCollect(createReqVO));
    }

//    @PutMapping("/update")
//    @Operation(summary = "更新收藏信息")
////    @PreAuthorize("@ss.hasPermission('biz:collect:update')")
//    public CommonResult<Boolean> updateCollect(@Valid @RequestBody CollectSaveReqVO updateReqVO) {
//        collectService.updateCollect(updateReqVO);
//        return success(true);
//    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除收藏信息")
//    @Parameter(name = "id", description = "编号", required = true)
////    @PreAuthorize("@ss.hasPermission('biz:collect:delete')")
//    public CommonResult<Boolean> deleteCollect(@RequestParam("id") Long id) {
//        collectService.deleteCollect(id);
//        return success(true);
//    }

//    @DeleteMapping("/delete-list")
//    @Parameter(name = "ids", description = "编号", required = true)
//    @Operation(summary = "批量删除收藏信息")
//                @PreAuthorize("@ss.hasPermission('biz:collect:delete')")
//    public CommonResult<Boolean> deleteCollectList(@RequestParam("ids") List<Long> ids) {
//        collectService.deleteCollectListByIds(ids);
//        return success(true);
//    }

//    @GetMapping("/get")
//    @Operation(summary = "获得收藏信息")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
////    @PreAuthorize("@ss.hasPermission('biz:collect:query')")
//    public CommonResult<CollectRespVO> getCollect(@RequestParam("id") Long id) {
//        CollectDO collect = collectService.getCollect(id);
//        return success(BeanUtils.toBean(collect, CollectRespVO.class));
//    }

    @GetMapping("/page")
    @Operation(summary = "获得收藏信息分页")
//    @PreAuthorize("@ss.hasPermission('biz:collect:query')")
    public CommonResult<PageResult<CollectRespVO>> getCollectPage(@Valid CollectPageReqVO pageReqVO) {
        PageResult<CollectDO> pageResult = collectService.getCollectPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CollectRespVO.class));
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出收藏信息 Excel")
////    @PreAuthorize("@ss.hasPermission('biz:collect:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportCollectExcel(@Valid CollectPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<CollectDO> list = collectService.getCollectPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "收藏信息.xls", "数据", CollectRespVO.class,
//                        BeanUtils.toBean(list, CollectRespVO.class));
//    }

}